package com.vcs.util;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Util {

	public static Date currentDate() {
		Calendar calendar = Calendar.getInstance();
		return calendar.getTime();
	}

	/**
	 * Valid email must contain atleast one @ and . character Eg.
	 * myjob.vcs@gmail.com
	 * 
	 * @param emailId
	 * @return true if email is valid else returns false.
	 */

	public static boolean isValidEmailAddress(String emailId) {

		Pattern pattern = null;
		Matcher matcher = null;

		final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

		pattern = Pattern.compile(EMAIL_PATTERN);

		matcher = pattern.matcher(emailId);
		return matcher.matches();

		/*
		 * if (emailId == null || emailId.length() < 5) { return false; }
		 * 
		 * if (emailId.contains("@") && emailId.contains(".") &&
		 * emailId.lastIndexOf(".") > emailId.lastIndexOf("@")){ return true;
		 * }else{ return false; }
		 */
	}
	
	public void storePropertyToXmlFile(String key, String value){
		// TODO THIS METHOD IS NOT BEING USED.. TO BE REMOVED WHILE REFRACTORING
		Properties properties = new Properties();
		try {
			OutputStream os = new FileOutputStream("");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public String loadPropertyFromXmlFile(String key){
		// TODO THIS METHOD IS NOT BEING USED.. TO BE REMOVED WHILE REFRACTORING
		return null;
	}
}
